package com.atguigu.jinx.enums.alipay;

/**
 * @author steve
 * @date 2025/08/29 15:17
 */

import java.util.HashMap;
import java.util.Map;

/**
 * 支付宝订单状态枚举
 */
public enum AlipayOrderStatusEnum {

    TRADE_CREATED("TRADE_CREATED", "订单创建"),
    WAIT_PAY("WAIT_PAY", "等待支付"),
    TIMEOUT_CLOSED("TIMEOUT_CLOSED", "超时取消"),
    PAID("PAID", "支付成功"),
    PARTIAL_DELIVERED("PARTIAL_DELIVERED", "部分发货"),
    DELIVERED("DELIVERED", "全部发货"),
    RECEIVED_CONFIRM("RECEIVED_CONFIRM", "确认收货"),
    REFUND_CLOSED("REFUND_CLOSED", "全部退款"),
    CONFIRMED("CONFIRMED", "已确认"),
    CANCELLED("CANCELLED", "预约失败"),
    TO_BE_CHECK_IN("TO_BE_CHECK_IN", "待入住"),
    CHECK_IN("CHECK_IN", "已入住"),
    HAVE_STAY("HAVE_STAY", "已续住"),
    TO_CHECK_OUT("TO_CHECK_OUT", "待退房"),
    CHECK_OUT("CHECK_OUT", "已退房"),
    FINISHED("FINISHED", "已完结"),
    GIVE_BACK("GIVE_BACK", "已归还"),
    MERCHANT_CONFIRMED("MERCHANT_CONFIRMED", "商户已确认"),
    WAIT_CONFIRM("WAIT_CONFIRM", "订单等待确认状态"),
    WAIT_DELIVER("WAIT_DELIVER", "订单待发货状态"),
    DELIVERED_USED("DELIVERED_USED", "订单履约被使用"),
    SUCCESS("SUCCESS", "订单成功"),
    CANCEL_CLOSED("CANCEL_CLOSED", "订单撤销关闭"),
    MERCHANT_CONFIRM_SUCCESSED("MERCHANT_CONFIRM_SUCCESSED", "商户确认成功"),
    MERCHANT_CONFIRM_FAILED("MERCHANT_CONFIRM_FAILED", "商户确认成功失败"),
    INIT("INIT", "订单初始状态");

    private final String code;
    private final String desc;

    AlipayOrderStatusEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    // ============ 反查工具 ============

    private static final Map<String, AlipayOrderStatusEnum> CODE_MAP = new HashMap<>();

    static {
        for (AlipayOrderStatusEnum status : AlipayOrderStatusEnum.values()) {
            CODE_MAP.put(status.getCode(), status);
        }
    }

    /**
     * 根据 code 获取枚举
     */
    public static AlipayOrderStatusEnum fromCode(String code) {
        return CODE_MAP.get(code);
    }

    /**
     * 根据 code 获取中文描述
     */
    public static String getDescByCode(String code) {
        AlipayOrderStatusEnum status = fromCode(code);
        return status != null ? status.getDesc() : "未知状态";
    }
}

